
package org.bridgen.lang.semantics.ast;
import java.util.*;



public class BridgeDecl extends Element implements Cloneable {
    public void flushCache() {
        super.flushCache();
    }
     @SuppressWarnings({"unchecked", "cast"})  public BridgeDecl clone() throws CloneNotSupportedException {
        BridgeDecl node = (BridgeDecl)super.clone();
        node.in$Circle(false);
        node.is$Final(false);
    return node;
    }
     @SuppressWarnings({"unchecked", "cast"})  public BridgeDecl copy() {
      try {
          BridgeDecl node = (BridgeDecl)clone();
          if(children != null) node.children = (ASTNode[])children.clone();
          return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
    }
     @SuppressWarnings({"unchecked", "cast"})  public BridgeDecl fullCopy() {
        BridgeDecl res = (BridgeDecl)copy();
        for(int i = 0; i < getNumChildNoTransform(); i++) {
          ASTNode node = getChildNoTransform(i);
          if(node != null) node = node.fullCopy();
          res.setChild(node, i);
        }
        return res;
    }
    // Declared in PrettyPrint.jrag at line 219

    
    public void pp(StringBuffer buf) {
    	buf.append(indent() + "bridge from ");
    	getStart().pp(buf);
    	buf.append(" to ");
    	getEnd().pp(buf);
    	if (hasWhenExpr()) {
    		buf.append(" when (");
    		getWhenExpr().pp(buf);
    		buf.append(")");
    	}	
    	buf.append(";\n");
    }

    // Declared in bridgit.ast at line 3
    // Declared in bridgit.ast line 40

    public BridgeDecl() {
        super();

        setChild(new Opt(), 2);

    }

    // Declared in bridgit.ast at line 11


    // Declared in bridgit.ast line 40
    public BridgeDecl(NodeUse p0, NodeUse p1, Opt<Expr> p2) {
        setChild(p0, 0);
        setChild(p1, 1);
        setChild(p2, 2);
    }

    // Declared in bridgit.ast at line 17


  protected int numChildren() {
    return 3;
  }

    // Declared in bridgit.ast at line 20

  public boolean mayHaveRewrite() { return false; }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 40
    public void setStart(NodeUse node) {
        setChild(node, 0);
    }

    // Declared in bridgit.ast at line 5

    public NodeUse getStart() {
        return (NodeUse)getChild(0);
    }

    // Declared in bridgit.ast at line 9


    public NodeUse getStartNoTransform() {
        return (NodeUse)getChildNoTransform(0);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 40
    public void setEnd(NodeUse node) {
        setChild(node, 1);
    }

    // Declared in bridgit.ast at line 5

    public NodeUse getEnd() {
        return (NodeUse)getChild(1);
    }

    // Declared in bridgit.ast at line 9


    public NodeUse getEndNoTransform() {
        return (NodeUse)getChildNoTransform(1);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 40
    public void setWhenExprOpt(Opt<Expr> opt) {
        setChild(opt, 2);
    }

    // Declared in bridgit.ast at line 6


    public boolean hasWhenExpr() {
        return getWhenExprOpt().getNumChild() != 0;
    }

    // Declared in bridgit.ast at line 10


     @SuppressWarnings({"unchecked", "cast"})  public Expr getWhenExpr() {
        return (Expr)getWhenExprOpt().getChild(0);
    }

    // Declared in bridgit.ast at line 14


    public void setWhenExpr(Expr node) {
        getWhenExprOpt().setChild(node, 0);
    }

    // Declared in bridgit.ast at line 17

     @SuppressWarnings({"unchecked", "cast"})  public Opt<Expr> getWhenExprOpt() {
        return (Opt<Expr>)getChild(2);
    }

    // Declared in bridgit.ast at line 21


     @SuppressWarnings({"unchecked", "cast"})  public Opt<Expr> getWhenExprOptNoTransform() {
        return (Opt<Expr>)getChildNoTransform(2);
    }

    // Declared in NameAnalysis.jrag at line 319
 @SuppressWarnings({"unchecked", "cast"})     public boolean isBridgeDecl() {
        boolean isBridgeDecl_value = isBridgeDecl_compute();
        return isBridgeDecl_value;
    }

    private boolean isBridgeDecl_compute() {  return true;  }

    // Declared in NameAnalysis.jrag at line 321
 @SuppressWarnings({"unchecked", "cast"})     public boolean includes(String island) {
        boolean includes_String_value = includes_compute(island);
        return includes_String_value;
    }

    private boolean includes_compute(String island) {  return getStart().getName().equals(island) || 
		getEnd().getName().equals(island);  }

    // Declared in TypeAnalysis.jrag at line 94
 @SuppressWarnings({"unchecked", "cast"})     public boolean isStart(String name) {
        boolean isStart_String_value = isStart_compute(name);
        return isStart_String_value;
    }

    private boolean isStart_compute(String name) {  return getStart().getName().equals(name);  }

    // Declared in TypeAnalysis.jrag at line 95
 @SuppressWarnings({"unchecked", "cast"})     public boolean isEnd(String name) {
        boolean isEnd_String_value = isEnd_compute(name);
        return isEnd_String_value;
    }

    private boolean isEnd_compute(String name) {  return getEnd().getName().equals(name);  }

    // Declared in PrettyPrint.jrag at line 29
    public String Define_String_indent(ASTNode caller, ASTNode child) {
        if(caller == getWhenExprOptNoTransform()) {
            return indent() + "  ";
        }
        return getParent().Define_String_indent(this, caller);
    }

    // Declared in NameAnalysis.jrag at line 190
    public NodeUse Define_NodeUse_lookupVariable(ASTNode caller, ASTNode child, String name) {
        if(caller == getWhenExprOptNoTransform()){
		if (name.equals("start")) {
			return getStart();
		} else if (name.equals("end")) {
			return getEnd();
		}
		return null;
	}
        return getParent().Define_NodeUse_lookupVariable(this, caller, name);
    }

public ASTNode rewriteTo() {
    return super.rewriteTo();
}

}
